package ai.basic;

import java.io.Serializable;

public class Pattern implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private short[] value;

	public short[] getValue() {
		return value;
	}

	public void setValue(short[] pattern) {
		this.value = pattern;
	}
	
	/**
	 * 0 1 2 3 4 5 6
	 * 1;2;3;5;1;3;2
	 *   t t t f t f
	 *   
	 * -+ = t
	 * +- = f
	 * @return form of pattern with an array of boolean elements.
	 */
	public boolean[] getPatternForm(){
		boolean[]form = new boolean[this.value.length-1];
		for (int i = 1; i < this.value.length; i++) {
			form[i-1]=(this.value[i-1]<this.value[i]);
		}
		return form;
	}

	public String formToString(){
		StringBuffer str = new StringBuffer();
		boolean[]tmp = this.getPatternForm();
		for (int i = 0; i < tmp.length; i++) {
			str.append((tmp[i]?"t":"f")+(((i+1)<tmp.length)?";":""));
		}
		return str.toString();
	}
	
	public String toString(){
		StringBuffer str = new StringBuffer();
		for (int i = 0; i < value.length; i++) {
			str.append(value[i]+(((i+1)<value.length)?";":""));
		}
		return str.toString();
	}
	
	public static boolean areEquals(Pattern a, Pattern b){
		boolean[]patternA = a.getPatternForm(),patternB = b.getPatternForm();
		if(patternA.length != patternB.length){return false;}
		for (int i = 0; i < patternA.length; i++) {
			if(patternA[i]!=patternB[i]){
				return false;
			}
		}
		return true;
	}
}
